home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / os2 / inadv095.zip / import.cmd < prev    next >
OS/2 REXX Batch file  |  1996-05-30  |  6KB  |  180 lines

  1. /* 
  2.  
  3. Import WebExplorers's quicklist into Internet Adventurer !
  4. by Kim Rasmussen - based upon another rexx script by Eony G. Flatscher
  5.  
  6. Original comment:
  7.  
  8. program: wequickl.cmd
  9. type:    REXXSAA-OS/2
  10. purpose: read WebExplorer's quicklist entries and generate 
  11. WPS-URL-objects
  12. version: 1.0
  13. date:    1995-06-05
  14.  
  15. usage:   wequickl
  16.          ... generates WPS-URL-objects from WE-quicklist in explore.ini
  17. author:  Rony G. Flatscher, Wirtschaftsuniversitaet/Vienna
  18.  
  19. standard disclaimer:
  20.  
  21. All rights reserved, copyrighted 1995, no guarantee that it works without
  22. errors, etc. etc.
  23.  
  24. donated to the public domain granted that you are not charging anything
  25. (money etc.) for it and derivates based upon it, as you did not write it,
  26. etc. if that holds you may bundle it with commercial programs too
  27. */
  28.  
  29.  
  30. IF RxFuncQuery('SysLoadFuncs') THEN
  31. DO
  32.     /* load the RexxUtil-load-function                                        */
  33.     CALL RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  34.     /* load all the Sys* utilities via "SysLoadFuncs"                         */
  35.     CALL SysLoadFuncs
  36. END
  37.  
  38. say "Trying to load/register Internet Adventurer REXX API"
  39. if RxFuncQuery("IARX_Register") <> 0 then do
  40.    rc = RxFuncAdd("IARX_Register","IA_UTILS","IARX_Register")
  41.    if rc <> 0 then do
  42.       say "-------------------------------------"
  43.       say "Error loading Internet Adventurer API"
  44.       say "-------------------------------------"
  45.       exit(1)
  46.    end
  47. end
  48.  
  49. rc = IARX_Register();
  50. if rc then do
  51.    say "-------------------------------------"
  52.    say "Error loading Internet Adventurer API"
  53.    say "-------------------------------------"
  54.    exit(1)
  55. end
  56.  
  57. say "Opening database"
  58. ptr = IARX_QOpenDatabase();
  59. if length(ptr) > 0 then do
  60.    say "-------------------------------------"
  61.    say "Opening database gave this:" ptr
  62.    say "-------------------------------------"
  63.    exit(1)
  64. end
  65.  
  66. say "Database opened"
  67.                                              /* get full path for explore.ini */
  68. explore_ini = VALUE("ETC", , "OS2ENVIRONMENT") || "\explore.ini"
  69.  
  70. IF STREAM(explore_ini, "C", "QUERY EXISTS") = "" THEN
  71.    CALL error explore_ini": WebExplorer INI-file does not exist !"
  72.  
  73. /* get quicklist entries (titles and URLs)                                    */
  74.  
  75. i = 0                                           /* counter for array index    */
  76. quicklist_found = 0                             /* boolean, false             */
  77. quicklist.0 = 0                                 /* indicate no items in array */
  78. url_next    = 0                                 /* indicate if URL expected   */
  79.  
  80. CALL STREAM explore_ini, "C", "OPEN READ"       /* open file for reading only */
  81. DO WHILE CHARS(explore_ini) > 0                 /* as long as lines left      */
  82.    line = LINEIN(explore_ini)                   /* read line                  */
  83.  
  84.    IF LEFT(line, 1) = "[" THEN                  /* new section found          */
  85.    DO
  86.       IF \quicklist_found THEN                  /* quicklist section ?        */
  87.       DO
  88.          IF TRANSLATE(line) = "[QUICKLIST]" THEN  /* is it the quicklist part?*/
  89.             quicklist_found = 1
  90.          ITERATE                                /* jump to top, read next line*/
  91.       END
  92.       ELSE                                      /* quicklist section is over  */
  93.          LEAVE
  94.    END
  95.  
  96.    IF \quicklist_found THEN ITERATE             /* skip line                  */
  97.  
  98.    IF \url_next THEN                            /* title in hand              */
  99.    DO
  100.       i = i + 1                                 /* new entry, increase index  */
  101.       PARSE VAR line "quicklist= " title        /* parse URL itself           */
  102.       quicklist.i.eTitle = title                /* save title of URL          */
  103.    END
  104.    ELSE
  105.       quicklist.i.eURL   = line                 /* save URL                   */
  106.  
  107.    url_next = \url_next                         /* switch boolean value       */
  108. END
  109.  
  110. quicklist.0 = MAX(0, i - 1)                     /* save # of items in array   */
  111. CALL STREAM explore_ini, "C", "CLOSE"           /* close input file           */
  112.  
  113. IF quicklist.0 = 0 THEN
  114.    CALL error explore_ini || ": no quicklist items found!"
  115.  
  116.  
  117. q.id = 0
  118. q.parent = 0
  119. q.children = 0
  120. q.type = 0
  121. q.title = "Imported from WebExplorer"
  122. q.nick = ""
  123. q.url = ""
  124.  
  125. rc = IARX_QCreate("q")
  126. if rc <> 0 then do
  127.    say "Unable to create group - aborting..."
  128.    rc = IARX_QCloseDatabase()
  129.    exit
  130. end
  131.  
  132. parent_id = q.id
  133.  
  134. /* create WE-objects, if they don't exist yet in top folder 
  135. *******************/
  136. DO i = quicklist.0 TO 1 BY -1                   /* loop over array            */
  137.    SAY right(i,3) quicklist.i.eTitle            /* show index, URL-title      */
  138.    SAY right("", 3) quicklist.i.eURL            /* show URL                   */
  139.  
  140.    q.id = 0
  141.    q.parent = parent_id
  142.    q.children = 0
  143.    q.type = 1
  144.    q.title = quicklist.i.eTitle
  145.    q.nick = ""
  146.    q.url = quicklist.i.eURL
  147.  
  148.    rc = IARX_QCreate("q")
  149.    if rc <> 0 then
  150.       say "Can't create item - error" rc
  151.    else
  152.       say "Item created"
  153. end
  154.  
  155. SAY
  156. SAY "total of" quicklist.0 "quicklist entries processed."
  157.  
  158. rc = IARX_QCloseDatabase()
  159. EXIT
  160.  
  161. /*
  162.    little procedure, to tell whether creation was successfully, 
  163.    expects boolean (0 = false, 1 = true)
  164. */
  165. FEEDBACK_MESSAGE: PROCEDURE
  166.    IF ARG(1) THEN RETURN "successful."
  167.              ELSE RETURN "*** NOT succesful *** (one reason: maybe it exists ?)"
  168. /*
  169.    procedure to tell error and exit with a negative return code
  170. */
  171. ERROR:
  172.    SAY "ERROR:" ARG(1) "aborting ..."
  173.    rc = IARX_QCloseDatabase()
  174.    EXIT -1
  175.  
  176.  
  177.  
  178.  
  179.  
  180.